package wre.logic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import edu.smu.tspell.wordnet.Synset;
import edu.smu.tspell.wordnet.WordNetDatabase;

public class InputParser {
	WordNetDatabase database;

	private InputParser() {

	}

	public static InputParser getInstance() {
		// Wordnet must be installed on your system. This property points to the
		// location of the database files
		System.setProperty("wordnet.database.dir",
				"C:\\Program Files (x86)\\WordNet\\2.1\\dict");
		InputParser inputParser = new InputParser();
		WordNetDatabase database = WordNetDatabase.getFileInstance();
		inputParser.setDatabase(database);
		return inputParser;

	}

	private void setDatabase(WordNetDatabase database) {
		this.database = database;
	}

	public List<String> parseInput(String input) {
		List<String> words = new ArrayList<String>();
		String[] split = input.split("\\W");
		for (String word : split) {
			String myWord = word.trim().toLowerCase();
			Synset[] synsets = database.getSynsets(myWord);
			for (Synset synset : synsets) {
				words.addAll(Arrays.asList(synset.getWordForms()));
			}
		}
		Set<String> set = new HashSet<String>(words);
		ArrayList<String> uniqueList = new ArrayList<String>(set);
		return uniqueList;

	}
}
